import module namespace common = "http://www.metaphoricalweb.com/xmlns/common" at "/xrai/common/xq/common.xq";

    let $type := common:get-parameter("type","")
    let $object := common:get-new($type)
    let $format := common:get-parameter("format","xml")
    let $result := 
    if ($format = "xml") then (util:declare-option("exist:serialize","media-type=text/xml"),$object) else
    if ($format = "atom") then 
    (util:declare-option("exist:serialize","media-type=application/atom+xml"),
    <atom:feed xmlns:atom="http://www.w3.org/2005/Atom">
         <atom:title>Results of getnew</atom:title>
         <atom:author>CASRAI.org</atom:author>
         <atom:id>{util:uuid()}</atom:id>
         <atom:issued>{current-dateTime()}</atom:issued>
         <atom:modified>{current-dateTime()}</atom:modified>
         <atom:created>{current-dateTime()}</atom:created>
         <atom:link href="To Be Determined"/>
         <atom:category schema="xrai" term="{$type}"/>     
        <atom:entry>
             <atom:title>{string($object//*:Metadata/*:Title)}</atom:title>
             <atom:author>CASRAI.org</atom:author>
             <atom:id>{util:uuid()}</atom:id>
             <atom:issued>{string($object//*:Metadata/*:DateCreated)}</atom:issued>
             <atom:modified>{string($object//*:Metadata/*:DateLastModified)}</atom:modified>
             <atom:created>{string($object//*:Metadata/*:DateCreated)}</atom:created>
             <atom:link href="http://localhost:8080/exist/rest//db/xrai/common/xq/editor.xq?id=new;type=cv"/>
             <atom:category schema="xrai" term="{$type}"/>     
            <atom:content type="application/xml">{$object}</atom:content>
        </atom:entry>
    </atom:feed>    )
    else (util:declare-option("exist:serialize","media-type=application/xml"),$object)
    return $result
